import { Bus, CHART_KLINE__ITEM, CHART_KLINE__LIST, CONN_ACTIVITY, CONN_CLEVER, CONN_RANK } from "../connetion/Bus";
import { IBroadcast } from "./IBroadcast";

export class CleverBroadcast extends IBroadcast {
    channelParam: any = {
        event: "subscribe",
        symbol: "all",
        topic: "on_chain",
        interval: "S1"
    };
    channelStr = "";

    subscribe(): void {
        this.unSubscribe();
        if (!this.channelParam) {
            console.log("订阅参数未初始化");
            return;
        }
        this.channelStr = JSON.stringify(this.channelParam);
        this.send(this.channelStr);
    }

    unSubscribe(): void {
        // console.warn("取消订阅")
        if (!this.channelStr) return;

        const obj = JSON.parse(this.channelStr);
        obj.event = "unsubscribe";
        this.send(JSON.stringify(obj));
    }

    handle(jsondata: any): void {
        Bus.emit(CONN_CLEVER, jsondata);
    }
}
